package com.ruoyi.common.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.pms.entity.YytAcupunctureType;
import com.ruoyi.common.pms.dao.YytAcupunctureTypeMapper;
import com.ruoyi.common.pms.service.YytAcupunctureTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.vo.AcupunctureTypeVo;
import com.xkzhangsan.time.utils.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* <p>
    *  服务实现类
    * </p>
*
* @author huangshun
* @since 2022-03-22
*/
@Service
public class YytAcupunctureTypeServiceImpl extends ServiceImpl<YytAcupunctureTypeMapper, YytAcupunctureType> implements YytAcupunctureTypeService {

    @Resource
    private YytAcupunctureTypeMapper yytAcupunctureTypeMapper;

    @Override
    public List<AcupunctureTypeVo> getTypeList() {
        // 返回的数据
        List<AcupunctureTypeVo> resultList = new ArrayList<>();

        QueryWrapper<YytAcupunctureType> wrapper = new QueryWrapper<>();
        wrapper.eq("father", 0).orderByAsc("three_id");
        // 获取第一层数据
        List<YytAcupunctureType> acupunctureTypes = yytAcupunctureTypeMapper.selectList(wrapper);

        // 遍历第一层  获取子数据
        for (YytAcupunctureType yt: acupunctureTypes){
            AcupunctureTypeVo acupunctureTypeVo = new AcupunctureTypeVo();
            BeanUtils.copyProperties(yt, acupunctureTypeVo);
            // 获取子节点
            QueryWrapper<YytAcupunctureType> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("father", yt.getThreeId()).orderByAsc("three_id");

            List<YytAcupunctureType> yytAcupunctureTypes = yytAcupunctureTypeMapper.selectList(wrapper1);
            acupunctureTypeVo.setChildList(yytAcupunctureTypes);

            resultList.add(acupunctureTypeVo);

        }


        return resultList;
    }
}
